package org.zyl.util.map.sql;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class SqlParameter implements Serializable{
	private static final long serialVersionUID = 1L;
	
	private Map<String, Object> paramMap = new HashMap<String, Object>();
	private SqlParameter(){}

	public static SqlParameter getParameter() {
		return new SqlParameter();
	}

	public SqlParameter addLimit(int pageNo,int pageSize){
		paramMap.put("offset", (pageNo-1)*pageSize);
		paramMap.put("rows", pageSize);
		return this;
	}
	public SqlParameter addOrder(String field,Order o){
		if (field==null||o==null||"null".equals(field+"")) {
			return this;
		}
		
		paramMap.put("order_by_column", field);
		paramMap.put("order_by", o.getCode());
		return this;
	}
	public SqlParameter addQuery(String key,Object value){
		paramMap.put(key, value);
		return this;
	}
	public SqlParameter addUpdate(String key,Object value){
		paramMap.put("update"+((key.charAt(0)+"").toUpperCase())+key.substring(1, key.length()), value);
		return this;
	}
	
	public SqlParameter clear(){
		paramMap.clear();
		return this;
	}
	
	public Map<String,Object> getMap(){
		return paramMap;
	}

}